< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03120301.xhp

(section: format) (bookmark: bm_id3153539)
Format function

Format 関数

Format Function [Runtime]
Format 関数 [実行時](hd_id3153539.1)

Converts a number to a string, and then formats it according to the format that you specify.
与えられた数値を文字列に変換してから、指定の書式にフォーマットします。(par_id3156042.2)

(/section: format)

Syntax:
構文:(hd_id3145090.4)

Format (Number [, Format As String])
Format (Number [, Format As String])(par_id3153527.5)

Return value:
戻り値:(hd_id3149178.6)

String
文字列(par_id3148474.7)

Parameters:
パラメータ:(hd_id3159176.8)

Number: Numeric expression that you want to convert to a formatted string.
Number: 書式設定された文字列にフォーマットさせる数値表式。(par_id3149415.9)

Format: String that specifies the format code for the number. If Format is omitted, the Format function works like the Str function.
Format: 数値の書式コードを指定する文字列Format 関数でこの Format 指定を省略すると、得られる結果は Str 関数の場合と同様のものとなります。(par_id3147531.10)

Formatting Codes
書式コード(hd_id3147561.47)

The following list describes the codes that you can use for formatting a number:
下記の一覧は、数値を書式化する際のコードをまとめたものです。(par_id3147265.11)

0: If Number has a digit at the position of the 0 in the format code, the digit is displayed, otherwise a zero is displayed.
0: 書式コード中の 0 は、Number の該当桁の数字を表示させるよう指定する記号で、該当桁に数値が無い場合は 0 を表示させます。(par_id3153380.12)

If Number has fewer digits than the number of zeros in the format code, (on either side of the decimal), leading or trailing zeros are displayed. If the number has more digits to the left of the decimal separator than the amount of zeros in the format code, the additional digits are displayed without formatting.
書式コードに指定した0の桁数よりも Number の数値の桁が小さい場合 (整数部および小数部) は、先頭側および末尾側に 0 が追加表示されます。書式コード中の 0 の桁数よりも数値の整数部の桁が大きい場合は、不足分の桁が補われる形で、整数部がそのまま表示されます。(par_id3151210.13)

Decimal places in the number are rounded according to the number of zeros that appear after the decimal separator in the Format code.
数値の小数部は、Format コードの小数部に指定する 0 の桁数に合わせて丸められます。(par_id3151176.14)

#: If Number contains a digit at the position of the # placeholder in the Format code, the digit is displayed, otherwise nothing is displayed at this position.
#: Format コード中の # プレースホルダは、Number の該当桁の数字を表示させるよう指定する記号で、該当桁に数値が無い場合は何も表示させません。(par_id3154123.15)

This symbol works like the 0, except that leading or trailing zeroes are not displayed if there are more # characters in the format code than digits in the number. Only the relevant digits of the number are displayed.
この書式コードは 0 と同様の機能を担っていますが、書式コード側の # の桁数より数値側の桁が小さくても、先頭側および末尾側に 0 が追加表示されない点が異なります。表示されるのは、数値側に実在する桁の数字だけです。(par_id3148452.16)

.: The decimal placeholder determines the number of decimal places to the left and right of the decimal separator.
.: 小数点プレースホルダは、小数点の位置を指定する記号で、この位置に応じて整数部および小数部の桁数も規定されます。(par_id3159150.17)

If the format code contains only # placeholders to the left of this symbol, numbers less than 1 begin with a decimal separator. To always display a leading zero with fractional numbers, use 0 as a placeholder for the first digit to the left of the decimal separator.
この記号の左側を # プレースホルダだけで埋めた書式コードを使用すると、1 よりも小さい数値は、先頭が小数点で始まる書式で表示されます。このような場合の整数部に 0 を表示させるのであれば、書式コードの 1 の位の桁のプレースホルダとして0を指定します。(par_id3159252.18)

%: Multiplies the number by 100 and inserts the percent sign (%) where the number appears in the format code.
%: 数値を 100 倍して、書式コード中の該当箇所にパーセント記号 (%) を表示させます。(par_id3153368.19)

E- E+ e- e+ : If the format code contains at least one digit placeholder (0 or #) to the right of the symbol E-, E+, e-, or e+, the number is formatted in the scientific or exponential format. The letter E or e is inserted between the number and the exponent. The number of placeholders for digits to the right of the symbol determines the number of digits in the exponent.
E- E+ e- e+ :書式コード中で、E-、E+、e-、e+ のいずれかの記号の右側に数値プレースホルダ (0 ないし #) が 1 つでもあれば、数値を指数形式 (科学書式) で表示させます。この場合得られる結果では、数値と指数部の間に E ないし e が表示されます。この記号の右側にくる数値プレースホルダの数で、指数表示の桁数が決まります。(par_id3149481.20)

If the exponent is negative, a minus sign is displayed directly before an exponent with E-, E+, e-, e+. If the exponent is positive, a plus sign is only displayed before exponents with E+ or e+.
負の指数の場合は、E-、E+、e-、e+ による指数表示の直前にマイナス記号が表示されます。正の指数の場合は、E+ および e+ による指数表示にのみ、直前にプラス記号が表示されます。(par_id3149262.21)

The thousands delimiter is displayed if the format code contains the delimiter enclosed by digit placeholders (0 or #).
千単位の桁区切りを示す記号を表示させるには、書式コード中の数値プレースホルダの該当位置に区切り記号を指定しておく必要があります。(par_id3148617.23)

The use of a period as a thousands and decimal separator is dependent on the regional setting. When you enter a number directly in Basic source code, always use a period as decimal delimiter. The actual character displayed as a decimal separator depends on the number format in your system settings.
ピリオド記号が小数点と千単位の桁区切りのどちらに使われるかは、ロケール設定により決まります。 BASICのソースコード内で数値を直接記述するときは、常にピリオド記号を小数点の記号として使います。 小数点としてどの記号が実際に表示されるかは、システムの数値表式設定により決まります。(par_id3163713.29)

- + $ ( ) space: A plus (+), minus (-), dollar ($), space, or brackets entered directly in the format code is displayed as a literal character.
- + $ ( ) スペース記号 :書式コード中に、プラス記号 (+)、マイナス記号 (-)、ドル記号 ($)、スペース記号、かっこなどの記号を直接記入した場合は、そのままの記号として表示されます。(par_id3152887.24)

To display characters other than the ones listed here, you must precede it by a backslash (\), or enclose it in quotation marks (" ").
ここで説明したプレースホルダなどの記号を、本来の記号そのものとして表記させるには、バックスラッシュ記号 (\) を直前に付けるか、引用符 (" ") で囲む必要があります。(par_id3148576.25)

\ : The backslash displays the next character in the format code.
\ : 書式コード中のバックスラッシュ記号は、次に続く記号をそのまま表示させます。(par_id3153139.26)

Characters in the format code that have a special meaning can only be displayed as literal characters if they are preceded by a backslash. The backslash itself is not displayed, unless you enter a double backslash (\\) in the format code.
書式コード用に特定の機能を担っている文字の場合、本来の記号そのものとして表記させるには、バックスラッシュ記号を直前に付ける必要があります。同様に、バックスラッシュ記号そのものを表示させるには、書式コード中でバックスラッシュ記号を2つ続けて記入します (\\)。(par_id3153366.27)

Characters that must be preceded by a backslash in the format code in order to be displayed as literal characters are date- and time-formatting characters (a, c, d, h, m, n, p, q, s, t, w, y, /, :), numeric-formatting characters (#, 0, %, E, e, comma, period), and string-formatting characters (@, &, <, >, !).
バックスラッシュ記号を付けないと本来の記号として表示されない書式コード用文字には、日付および時刻の書式設定用文字 (a、c、d、h、m、n、p、q、s、t、w、y、/、:)、数値の書式設定用文字2(#、0、%、E、e、コンマ、ピリオド)、文字列の書式設定用文字 (@、&、<、>、!) が該当します。(par_id3155411.28)

You can also use the following predefined number formats. Except for "General Number", all of the predefined format codes return the number as a decimal number with two decimal places.
数値の書式設定には、事前定義された下記の書式コードも使用できます。「General Number」を除くこれらの書式コードは、どれも有効数字 2 桁の数値を返します。(par_id3145749.30)

If you use predefined formats, the name of the format must be enclosed in quotation marks.
こうした事前定義された書式コードは、書式コード名を引用符で囲んで使用します。(par_id3150113.31)

Predefined format
事前定義された書式コード(hd_id3149377.32)

General Number: Numbers are displayed as entered.
General Number: 与えられた数値をそのまま表示します。(par_id3154730.33)

Currency: Inserts a dollar sign in front of the number and encloses negative numbers in brackets.
Currency: 数値の前に通貨記号を挿入し、負の値の場合はかっこで囲みます。(par_id3153158.34)

Fixed: Displays at least one digit in front of the decimal separator.
Fixed: 1 より小さい小数の場合に 1 の位の桁の0を表示させます。(par_id3154490.35)

Standard: Displays numbers with a thousands separator.
Standard: 千単位の桁区切り記号を表示させます(par_id3153415.36)

Percent: Multiplies the number by 100 and appends a percent sign to the number.
Percent: 数値を 100 倍して、パーセント記号 (%) を表示させます。(par_id3150715.37)

Scientific: Displays numbers in scientific format (for example, 1.00E+03 for 1000).
科学: 数字を指数表現で表します (例;1000は1.00E+03 と表示されます )。(par_id3153836.38)

A format code can be divided into three sections that are separated by semicolons. The first part defines the format for positive values, the second part for negative values, and the third part for zero. If you only specify one format code, it applies to all numbers.
書式コードには、セミコロンを区切り記号として、3つのセクションを指定できます。1 番目のセクションは正の値に対する書式指定、2 番目のセクションは負の値に対する書式指定、3 番目のセクションはゼロに対する書式指定です。書式コードを 1 つだけ指定した場合は、これらすべての数値に対して適用されます。(par_id3153707.39)

(embed text/sbasic/shared/00000003.xhp#languageformat : linkinfo)

You can set the locale used for controlling the formatting numbers, dates and currencies in Office Basic in (in case of MAC)Office - Preferences(/in case of MAC)(in other case)Tools - Options(/in other case) - Language Settings - Languages. In Basic format codes, the decimal point (.) is always used as placeholder for the decimal separator defined in your locale and will be replaced by the corresponding character.
[PO-fuzzy@sbasic\shared.po] ※※※未訳※※※(par_id3153381.102)

The same applies to the locale settings for date, time and currency formats. The Basic format code will be interpreted and displayed according to your locale setting.
これは、日付、時間、通貨の書式設定とロケールの関係についても同様です。Basic の書式コードは、個々のロケール設定に応じて、適切な表示に変換されます。(par_id3150870.103)

(/embed text/sbasic/shared/00000003.xhp#languageformat)

(embed text/sbasic/shared/00000003.xhp#errorcode : linkinfo)

Error Codes

エラーコード(hd_id3152869.37)

(/embed text/sbasic/shared/00000003.xhp#errorcode)

(embed text/sbasic/shared/00000003.xhp#err5 : linkinfo)

5 Invalid procedure call
5 無効なプロシージャー呼び出しです (par_id3150891.41)

(/embed text/sbasic/shared/00000003.xhp#err5)

Example:
例:(hd_id3149019.40)

Sub ExampleFormat
Sub ExampleFormat(par_id3156054.41)

MsgBox Format(6328.2, "##,##0.00")
MsgBox Format(6328.2, "##,##0.00")(par_id3148993.42)

REM always use a period as decimal delimiter when you enter numbers in Basic source code.
REM BASICのソースコード内で数値を直接記述するときは、常にピリオド記号を小数点の記号として使います。(par_idN107A2.)

REM displays for example 6,328.20 in English locale, 6.328,20 in German locale.
REM ロケール設定が英語であれば 6,328.20 と表示し、ドイツ語であれば 6.328,20 と表示します。(par_id3147339.46)

End Sub
End Sub(par_id3156382.43)


< Prev / Next >